package com.lanju.dao;

import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Repository;

import com.lanju.entity.ZukeContract;

@Repository
public class ZuKeContractDao {
	
		private static final Log log = LogFactory.getLog(ZuKeContractDao.class);
	  
	    @PersistenceContext(unitName = "financialmarketingUnit")
		private EntityManager entityManager;
	    
	    public void saveContract(ZukeContract zukeContract){
	    	try {
	    		entityManager.persist(zukeContract);
			} catch (Exception e) {
				e.printStackTrace();
			}
	    }
	    
		public void updateConstract(ZukeContract zukeContract){
			try {
				entityManager.merge(zukeContract);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		public ZukeContract getContract(Map<String,Object> map){
			try {
				return entityManager.find(ZukeContract.class, map.get("contractId").toString());
			} catch (Exception e) {
				e.printStackTrace();
				return null;
			}
		}
		
		public void delContract(ZukeContract contract){
			try {
				entityManager.remove(contract);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		public List<ZukeContract> getContractList(Map<String,Object> map){
			try {
				StringBuffer sql=new StringBuffer();
				sql.append(" from ZukeContract where userId='"+map.get("userId").toString()+"' order by create_time desc");
				Query query=entityManager.createQuery(sql.toString());
				List<ZukeContract> list=query.getResultList();
				return list;
			} catch (Exception e) {
				e.printStackTrace();
				return null;
			}
		}
		
		public ZukeContract signComtract(ZukeContract contract){
			try {
				return entityManager.merge(contract);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return null;
		}
		
}
